package com.binarysoft.cmdhandler.common.system;

import java.util.StringTokenizer;

import common.framework.command.handler.AbstractCommandHandler;
import common.framework.command.server.Terminal;
import common.framework.dsb.annotation.DSBCmd;

@DSBCmd("sysem")
public class SystemCmdHandler extends AbstractCommandHandler {

	@Override
	public void handle(String args, Terminal terminal) throws Exception {
		terminal.println("");
		StringTokenizer stier = new StringTokenizer(args);
		int count = stier.countTokens();
		if (count < 2) {
			terminal.println(" system shutdown                 --shutdown server");
			terminal.println("");
			return;
		}
		stier.nextToken(); // command name
		String cmd = stier.nextToken(); // operation
		if ("shutdown".equalsIgnoreCase(cmd) && count == 2) {
			terminal.print("Are you sure to shutdown server?(Y/N)");
			String opt = terminal.read();
			if ("Y".equalsIgnoreCase(opt)) {
				terminal.println("");
				System.exit(0);
			}
		}
		terminal.println("");
	}// handle
}
